package cn.iocoder.yudao.module.yyzx.service.nurse_level;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_level.Nurse_levelDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.yyzx.dal.mysql.nurse_level.Nurse_levelMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.*;

/**
 * 护理级别 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class Nurse_levelServiceImpl implements Nurse_levelService {

    @Resource
    private Nurse_levelMapper nurse_levelMapper;

    @Override
    public Integer createNurse_level(Nurse_levelSaveReqVO createReqVO) {
        // 插入
        Nurse_levelDO nurse_level = BeanUtils.toBean(createReqVO, Nurse_levelDO.class);
        nurse_levelMapper.insert(nurse_level);
        // 返回
        return nurse_level.getId();
    }

    @Override
    public void updateNurse_level(Nurse_levelSaveReqVO updateReqVO) {
        // 校验存在
        validateNurse_levelExists(updateReqVO.getId());
        // 更新
        Nurse_levelDO updateObj = BeanUtils.toBean(updateReqVO, Nurse_levelDO.class);
        nurse_levelMapper.updateById(updateObj);
    }

    @Override
    public void deleteNurse_level(Integer id) {
        // 校验存在
        validateNurse_levelExists(id);
        // 删除
        nurse_levelMapper.deleteById(id);
    }

    private void validateNurse_levelExists(Integer id) {
        if (nurse_levelMapper.selectById(id) == null) {
            throw exception(NURSE_LEVEL_NOT_EXISTS);
        }
    }

    @Override
    public Nurse_levelDO getNurse_level(Integer id) {
        return nurse_levelMapper.selectById(id);
    }

    @Override
    public PageResult<Nurse_levelDO> getNurse_levelPage(Nurse_levelPageReqVO pageReqVO) {
        return nurse_levelMapper.selectPage(pageReqVO);
    }

}